import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;

/**
 * @author Egor Kulikov (egor@egork.net)
 */
public class TaskI {
	@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
	private InputReader in;
	private PrintWriter out;
	private static final int MOD = 1000000007;
	private long[][] c = new long[1001][1001];

	private static class Result {
		private int length = 0;
		private int length2 = 0;
		private long sum = 0;
	}

	private void solve() {
		try {
		init();
		int[] a = in.readIntArray(9);
		int queryCount = in.readInt();
		int sum = 0;
		for (int i = 0; i < 9; i++)
			sum += a[i];
		long[] tens = new long[sum + 1];
		tens[0] = 1;
		for (int i = 1; i <= sum; i++)
			tens[i] = (tens[i - 1] * 10) % MOD;
		long[] sumTens = new long[sum + 1];
		sumTens[0] = 1;
		for (int i = 1; i <= sum; i++)
			sumTens[i] = (sumTens[i - 1] + tens[i]) % MOD;
		for (int i = 0; i < queryCount; i++) {
			String u = in.readString();
			String v = in.readString();
			Result result = countResult(v, u, a, 0, sum, tens, sumTens);
			long coef = power(2, (result.length2 + MOD - 3) % (MOD - 1), MOD);
			out.println(coef + " " + ((coef * result.sum) % MOD));
		}
		} catch (ArrayIndexOutOfBoundsException e){}
	}

	private void applyResult(Result result, Result callResult, int sum, int step, long[] tens, int digit) {
		result.length = (result.length + callResult.length) % MOD;
		result.length2 = (result.length2 + callResult.length2) % (MOD - 1);
		result.sum = (result.sum + callResult.sum) % MOD;
		long digitSum = ((digit + 1) * tens[sum - step - 1]) % MOD;
		digitSum = (digitSum * callResult.length) % MOD;
		result.sum = (result.sum + digitSum) % MOD;
	}

	private Result countResult(String u, String v, int[] a, int step, int sum, long[] tens, long[] sumTens) {
		if (u.charAt(step) == v.charAt(step)) {
			int digit = u.charAt(step) - '1';
			a[digit]--;
			Result callResult = countResult(u, v, a, step + 1, sum, tens, sumTens);
			Result result = new Result();
			applyResult(result, callResult, sum, step, tens, digit);
			return result;
		}
		int firstDigit = u.charAt(step) - '1';
		int lastDigit = v.charAt(step) - '1';
		Result result = new Result();
		for (int i = firstDigit + 1; i < lastDigit; i++) {
			if (a[i] == 0)
				continue;
			a[i]--;
			Result callResult = countInternal(sum - step - 1, a, sumTens);
			applyResult(result, callResult, sum, step, tens, i);
			a[i]++;
		}
		a[firstDigit]--;
		Result callResult = countLast(u, a, step + 1, sum, tens, sumTens);
		applyResult(result, callResult, sum, step, tens, firstDigit);
		a[firstDigit]++;
		a[lastDigit]--;
		callResult = countFirst(v, a, step + 1, sum, tens, sumTens);
		applyResult(result, callResult, sum, step, tens, lastDigit);
		a[lastDigit]++;
		return result;
	}

	private Result countFirst(String u, int[] a, int step, int sum, long[] tens, long[] sumTens) {
		if (step == sum) {
			Result result = new Result();
			result.length = 1;
			result.length2 = 1;
			return result;
		}
		int digit = u.charAt(step) - '1';
		Result result = new Result();
		for (int i = 0; i < digit; i++) {
			if (a[i] == 0)
				continue;
			a[i]--;
			Result callResult = countInternal(sum - step - 1, a, sumTens);
			applyResult(result, callResult, sum, step, tens, i);
			a[i]++;
		}
		a[digit]--;
		Result callResult = countFirst(u, a, step + 1, sum, tens, sumTens);
		applyResult(result, callResult, sum, step, tens, digit);
		a[digit]++;
		return result;
	}

	private Result countLast(String u, int[] a, int step, int sum, long[] tens, long[] sumTens) {
		if (step == sum) {
			Result result = new Result();
			result.length = 1;
			result.length2 = 1;
			return result;
		}
		int digit = u.charAt(step) - '1';
		Result result = new Result();
		for (int i = digit + 1; i < 9; i++) {
			if (a[i] == 0)
				continue;
			a[i]--;
			Result callResult = countInternal(sum - step - 1, a, sumTens);
			applyResult(result, callResult, sum, step, tens, i);
			a[i]++;
		}
		a[digit]--;
		Result callResult = countLast(u, a, step + 1, sum, tens, sumTens);
		applyResult(result, callResult, sum, step, tens, digit);
		a[digit]++;
		return result;
	}

	private Result countInternal(int digits, int[] a, long[] sumTens) {
		Result result = new Result();
		if (digits == 0) {
			result.length = 1;
			result.length2 = 1;
			return result;
		}
		int totalLength = getCount(a);
		result.length = totalLength;
		result.length2 = (totalLength) % (MOD - 1);
		for (int i = 0; i < 9; i++) {
			if (a[i] != 0) {
				a[i]--;
				result.sum = (result.sum + (((getCount(a) * sumTens[digits - 1]) % MOD) * (i + 1)) % MOD) % MOD;
				a[i]++;
			}
		}
		return result;
	}

	private int getCount(int[] a) {
		int left = 0;
		int right = a[0];
		long result = 1;
		for (int i = 0; i < 8; i++) {
			left += a[i];
			right += a[i + 1];
			result = (result * c[right][left]) % MOD;
		}
		return (int) result;
	}

	private void init() {
		for (int i = 0; i <= 1000; i++) {
			c[i][0] = 1;
			for (int j = 1; j <= i; j++)
				c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
		}
	}	

	public static long power(long base, int exponent, int mod) {
		if (exponent == 0)
			return 1;
		long power = power(base, exponent >> 1, mod);
		power *= power;
		power %= mod;
		if ((exponent & 1) != 0) {
			power *= base;
			power %= mod;
		}
		return power;
	}
	
	public static void main(String[] args) {
		new TaskI().run();
	}

	private TaskI() {
		@SuppressWarnings({"UnusedDeclaration"})
		String id = getClass().getName().toLowerCase();
		//noinspection EmptyTryBlock
		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	private void run() {
		//noinspection InfiniteLoopStatement
//		int testCount = in.readInt();
//		for (int i = 0; i < testCount; i++)
//		while (true)
			solve();
		exit();
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private void exit() {
		out.close();
		System.exit(0);
	}

	@SuppressWarnings({"UnusedDeclaration"})
	private static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar, numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public int[] readIntArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = readInt();
			return array;
		}

		public long[] readLongArray(int size) {
			long[] array = new long[size];
			for (int i = 0; i < size; i++)
				array[i] = readLong();
			return array;
		}

		public double[] readDoubleArray(int size) {
			double[] array = new double[size];
			for (int i = 0; i < size; i++)
				array[i] = readDouble();
			return array;
		}

		public String[] readStringArray(int size) {
			String[] array = new String[size];
			for (int i = 0; i < size; i++)
				array[i] = readString();
			return array;
		}

		public char[][] readTable(int rowCount, int columnCount) {
			char[][] table = new char[rowCount][columnCount];
			for (int i = 0; i < rowCount; i++) {
				for (int j = 0; j < columnCount; j++)
					table[i][j] = readCharacter();
			}
			return table;
		}

		public void readIntArrays(int[]... arrays) {
			for (int i = 0; i < arrays[0].length; i++) {
				for (int j = 0; j < arrays.length; j++)
					arrays[j][i] = readInt();
			}
		}
	}
}
